package com.client.rel.utils;

import java.io.File;

import com.client.ConfigCons;
import com.ms.MsConfig;
import com.system.comm.utils.FrameFileUtil;
import com.system.comm.utils.FrameTimeUtil;

public class ClientUtil {

	/**
	 * 获取上传文件的目录<br>
	 * 如：/home/www/1/1.0.0/
	 * @param prjId
	 * @param version
	 * @return
	 */
	public static String getPrjPath(Integer prjId, String version) {
		String prjPath = ConfigCons.versionDir + File.separator + MsConfig.getClientId() + File.separator + prjId + File.separator + version + File.separator;
		FrameFileUtil.createDir(prjPath);
		return prjPath;
	}
	

	/**
	 * 转换特殊参数<br>
	 * 参数：
	 * 		{prj.path}:项目在客户端的路径
	 * 		{prj.name}:项目在客户端的名称包含后缀
	 * @param command
	 * @param prjId
	 * @return
	 */
	public static String convertCommand(String command, Integer prjId, String prjName, String version) {
		if(command.contains("[prj.path]")) {
			//处理项目路径
			command = command.replace("[prj.path]", ClientUtil.getPrjPath(prjId, version));
		}
		if(command.contains("[prj.name]")) {
			//处理项目名称
			command = command.replace("[prj.name]", prjName);
		}
		if(command.contains("[current.date]")) {
			//处理当前日期
			command = command.replace("[current.date]", FrameTimeUtil.parseString(FrameTimeUtil.getTime(), FrameTimeUtil.FMT_YYYYMMDD));
		}
		if(command.contains("[current.time]")) {
			//处理当前时间
			command = command.replace("[current.time]", FrameTimeUtil.parseString(FrameTimeUtil.getTime(), FrameTimeUtil.FMT_YYYYMMDDHHMMSS));
		}
		return command;
	}
}
